<?php
// .-----------------------------------------------------------------------------------
// |  Software: [HDPHP framework]
// |   Version: 2013.01
// |      Site: http://www.hdphp.com
// |-----------------------------------------------------------------------------------
// |    Author: 向军 <houdunwangxj@gmail.com>
// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------
// |   License: http://www.apache.org/licenses/LICENSE-2.0
// '-----------------------------------------------------------------------------------
class IndexControl extends CommonControl{
    // 网站首页
    function index(){

    	// 首页图片展示
    	$db = M('indeximgs');
    	$imgs = $db->limit(10)->all();

        // 友情链接
        $flinks = C('flink');
        $farr = explode('|',trim($flinks));
        $farr = array_map('trim', $farr);

        
    	// 首页显示文字栏目，默认只显示顶级栏目
        // $channel = $db->Table('info')->field('lid')->group('lid')->order('addtime desc,orders')->limit(5)->all();
        // $channel = $db->query("select a.lid,b.name from ica_info as a inner join ica_infolist as b where a.lid=b.id and b.pid=0 group by b.id order by b.orders,addtime desc,b.id desc");
        $channel = $db->Table('infolist')->field('id|lid,name')->where("pid=0")->all();
        // p($channel);
        $datalist = array();
        if(is_array($channel)){
            foreach($channel as $k=>$v){
                //$db = K('infolist');
                $lids = $this->db_infolist->getLids($v['lid']); 
                $lids = $lids?' and lid in('.$lids.')':' and lid='.$v['lid'];
                $list = $db->Table('info')->where("isshow=1".$lids)->order('orders,addtime desc,id desc')->limit(2)->all();
                // echo $db->getLastSql();
                // exit;
                $datalist[$v['name']] = $list;
            }
        }


        // p($datalist);
    	$this->assign('datalist',$datalist);//所有显示栏目及其文章
    	$this->assign('imgs',$imgs);//首页图片展示
        $this->assign('flinks',$farr);//友情链接
    	$this->display();
    }
}
?>